function fetchByPost(url, bd) {
    var con = org.jsoup.Jsoup.connect(url);
    con.requestBody(JSON.stringify(bd));
    con.ignoreContentType(true);
    return con.post().body().text();
}

function formatDate2(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '-' + m + '-' + d;
};

function formatDate(now) {
    var time = formatDate2(now)
    var date1 = new Date(now)
    var date2 = new Date()
    var date3 = date2.getTime() - date1.getTime()
    var days = Math.floor(date3 / (24 * 3600 * 1000))
    var leave1 = date3 % (24 * 3600 * 1000)
    var hours = Math.floor(leave1 / (3600 * 1000))
    var leave2 = leave1 % (3600 * 1000)
    var minutes = Math.floor(leave2 / (60 * 1000))
    var leave3 = leave2 % (60 * 1000)
    if (days < 1 && hours < 1) { return minutes + "分前" } else if (days < 1) { return hours + "小时 " + minutes + "分前" } else {
        if (days < 7) {
            return days + "天 " + hours + "小时前 "
        } else { return time }
    }
}

function formatTime(seconds) {
    if (isNaN(seconds) || seconds < 0) return "0:00"; // 处理无效输入

    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const remainingSeconds = seconds % 60;

    // 补零函数
    const pad = (num) => num < 10 ? `0${num}` : num;

    // 根据小时数动态选择格式
    if (hours > 0) {
        return `${hours}:${pad(minutes)}:${pad(remainingSeconds)}`;
    } else {
        return `${minutes}:${pad(remainingSeconds)}`;
    }
}

function giteeUrl(url, access_token = "") {
    const { java, source, cache } = this;
    if (access_token === null || access_token === '') {
        try {
            access_token = String(cache.get('gitee_tk'));
        } catch (err) { access_token = ''; }
    }
    return url + "?access_token=" + access_token;
}

function deleteCache(urls) {
    const { java, cache } = this;
    if (urls && urls.length > 0) {
        urls.forEach((item, index, array) => {
            // array 是原始数组的引用
            let yckey = java.md5Encode16(item);
            cache.delete(yckey);
        });
    }
    java.longToast('【清理代码缓存】\n\n已经清除远程代码缓存\n\n下一次使用将重新同步代码');
}

function purifyContent(content) {
    const { java } = this;
    let regex = /<p[^>]*?>[\s&nbsp;]*?<\/p>/g;
    content=content.replace(regex, "");
    regex = /<p[^>]*?>\s*?(<video[\s\S]*?video>)[\s\S]*?<\/p>/g;
    content = content.replace(regex, "$1");
    regex = /<p[^>]*?>\s*?(<iframe[\s\S]*?<\/iframe>)[\s\S]*?<\/p>/g;
    content = content.replace(regex, "$1");
    regex = /<p[^>]*?>\s*?(<img[\s\S]*?>)[\s\S]*?<\/p>/g;
    content = content.replace(regex, "$1");
    return content;
}

function wrapCommentUrl(url){
    return "<a href=\"" + url + "\" style=\" color: #0066cc;text-decoration: none;font-weight: bold;padding: 8px 12px;border-radius: 4px;background-color: #f0f0f0;display: inline-block;margin: 10px;float:right;\">查看评论</a>";
}

function Reload(e) {
    const { java, source, cookie, cache } = this;
    var jskey = java.md5Encode16(e);
    var etag = '';
    try {
        if (cache.get('etagtime' + jskey) && Date.now() - cache.get('etagtime' + jskey) < 600000) {
            etag = cache.get('etag' + jskey) || 'noetag';
        } else {
            etag = String(java.head(e, {}).header('etag'));
            cache.put('etagtime' + jskey, Date.now());
        }
    } catch {
        etag = cache.get('etag' + jskey) || 'noetag';
    }
    if (cache.get('etag' + jskey) && !new RegExp(etag).test(cache.get('etag' + jskey))) {
        cache.delete(jskey);
        etag = String(java.head(e, {}).header('etag'));
        cache.put('etag' + jskey, etag);
        cache.put('etagtime' + jskey, Date.now());
    }
    var res = String(java.importScript(e));
    return res;
}